package com.derive.education_service.web.agent.controller;

import com.derive.education_service.common.global.ResponseMessage;
import com.derive.education_service.entity.User;
import com.derive.education_service.web.agent.bean.dto.AgentAddDto;
import com.derive.education_service.web.agent.bean.dto.AgentUpDto;
import com.derive.education_service.web.agent.sevice.AgentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("agent")
@Validated
@Slf4j
public class AgentController {

    @Autowired
    private AgentService agentService;

    @GetMapping("getUserAgentBy")
    public ResponseMessage getUserAgentBy() {
        List<User> userList = agentService.getUserAgentBy();
        return ResponseMessage.createBySuccess(userList);
    }

    @PostMapping("addAgent")
    public ResponseMessage addAgent(@RequestPart("file") MultipartFile file, @Validated @RequestPart("agentAddDto") AgentAddDto agentAddDto) {
        return agentService.addAgent(file, agentAddDto);
    }

    @PostMapping("delAgent")
    public ResponseMessage delAgent(@NotNull(message = "id不能为空") int agentId) {
        return agentService.delAgent(agentId);
    }

    @PostMapping("upAgent")
    public ResponseMessage upAgent(@RequestPart("file") MultipartFile file, @Validated @RequestPart("agentUpDto") AgentUpDto agentUpDto) {
        return agentService.upAgent(file, agentUpDto);
    }

    @GetMapping("getAgentByOpenId")
    public ResponseMessage getAgentByOpenId(@NotBlank(message = "openId不能为空") String openId) {
        return agentService.getAgentByOpenId(openId);
    }
}
